import request from '@/utils/request'

import CustomForm from '../Form/index.vue'
import { deepClone } from '@/utils'
export default {
  components: { CustomForm },
  props: ['type'],
  data() {
    return {
      loading: false,
      visible: false,
      list: [],
      policyNameOptions: [
        {
          enCode: '1',
          fullName: '三合一'
        },
        {
          enCode: '2',
          fullName: '雇主责任险'
        },
        {
          enCode: '3',
          fullName: '公众责任险'
        },
        {
          enCode: '4',
          fullName: '财产一切险'
        },
        {
          enCode: '5',
          fullName: '公众责任险+雇主责任险'
        },
        {
          enCode: '6',
          fullName: '公众责任险+财产一切险'
        },
        {
          enCode: '7',
          fullName: '其他'
        }
      ],
      insuranceCompanyOptions: [
        {
          enCode: '1',
          fullName: '未办理'
        },
        {
          enCode: '2',
          fullName: '安亲保'
        },
        {
          enCode: '3',
          fullName: '放心保'
        },
        {
          enCode: '4',
          fullName: '平安保险'
        },
        {
          enCode: '5',
          fullName: '太平洋保险'
        },
        {
          enCode: '6',
          fullName: '中国人寿'
        },
        {
          enCode: '7',
          fullName: '阳光保险'
        },
        {
          enCode: '8',
          fullName: '其他'
        }
      ],
      formVisible: false
    }
  },
  computed: {},
  watch: {},
  created() {
    /*this.$store.dispatch('base/getDictionaryData', { sort: 'sex' }).then(res => {
      this.genderOptions = res
    });
    this.$store.dispatch("base/getDictionaryData", { sort: "Brand" }).then((res) => {
      this.brandOptions = res;
    });*/
  },
  mounted() {},
  methods: {
    goBack() {
      this.$emit('refresh', false)
    },
    refresh() {

    },
    getData() {
      this.list = []
      request({
        url: 'api/campus/insurance/records/' + this.campusId,
        method: 'get'
      })
        .then(res => {
          this.list = res.data
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },
    init(id) {
      this.campusId = id
      this.visible = true
      this.loading = true
      this.getData()
    },
    reset() {
      this.getData()
    },
    handleDel(id) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        type: 'warning'
      })
        .then(() => {
          request({
            url: `/api/campus/insurance/${id}`,
            method: 'DELETE'
          }).then(res => {
            this.$message({
              type: 'success',
              message: res.msg,
              onClose: () => {
                this.reset()
              }
            })
          })
        })
        .catch(() => {})
    },
    addOrUpdateHandle(id, isDetail) {
      this.formVisible = true
      this.$nextTick(() => {
        this.$refs.CustomForm.init(id, isDetail, this.campusId)
      })
    }
  }
}
